define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'questiongroup/index' + location.search,
                    add_url: 'questiongroup/add',
                    edit_url: 'questiongroup/edit',
                    del_url: 'questiongroup/del',
                    multi_url: 'questiongroup/multi',
                    import_url: 'questiongroup/import',
                    table: 'question_group',
                }
            });

            var table = $("#table");
             //当内容渲染完成给编辑按钮添加`data-area`属性，点击列表编辑按钮时全屏
             table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-add").data("area", ["100%", "100%"]);
                $(".btn-editone").data("area", ["100%", "100%"]);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'question_cate_pid_name', title: __('题库一级分类题'),operate: false},
                        {field: 'question_cate_name', title: __('题库分类'),operate: false},
                        {field: 'question_cate_id3_name', title: __('省份'),operate: false},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-question_cate_id").data("params", function (obj) {
                //obj为SelectPage对象
                return {custom: {pid: $("#c-question_cate_pid").val()}};
            });

            // 省份数据
            $("#c-question_cate_id3").data("params", function (obj) {
                //obj为SelectPage对象
                return {custom: {pid: $("#c-question_cate_id").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-question_cate_id").data("params", function (obj) {
                //obj为SelectPage对象
                return {custom: {pid: $("#c-question_cate_pid").val()}};
            });
             // 省份数据
             $("#c-question_cate_id3").data("params", function (obj) {
                //obj为SelectPage对象
                return {custom: {pid: $("#c-question_cate_id").val()}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"), function () {
                }, function () {
                }, function () {
                    let mode = $('input[name="row[mode]"]:checked').val()
                    $('#valid').click()
                    return valid_result;
                });
            },
        }
    };
    return Controller;
});
